﻿// ***********************************************************************
// Assembly         : STX.Service
// Author           : seven.x
// Created          : 03-04-2014
//
// Last Modified By : seven.x
// Last Modified On : 03-04-2014
// ***********************************************************************
// <copyright file="BizReadUserService.cs" company="驰创数码">
//     Copyright (c) 驰创数码. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************using System;

using System;
using System.Linq;
using Autofac;
using STX.Domain;
using STX.Repository;

namespace STX.Service
{

    /// <summary>
    /// Class BizReadUserService.
    /// </summary>
    public class BizReadUserService : BaseService<BizReadUser>
    {

        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="successAction">The success action.</param>
        /// <returns>System.Int64.</returns>
        /// <exception cref="System.Exception">此条信息已存在</exception>
        public override long Add(BizReadUser entity, Action<ITransactionContext, BizReadUser> successAction = null)
        {
            var repository = Transaction.GetRepository<BizReadUser>();
            var models = repository.FindAll()
                .Where(o => o.Type == entity.Type && o.InfoId == entity.InfoId && o.UId == entity.UId);
            if (models.Any())
            {
                throw new Exception("此条信息已存在");
            }
            repository.Add(entity);
            Transaction.Commit();
            return entity.Id;
        }

        



    }
}
